package cn.zenith.lucene.demo;

import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;

/**
 * lucene演示Demo类
 * 
 * @author zenith
 * @date 2014年3月27日 下午1:33:53
 */
public class LuceneBase {
	/**
	 * 抽象的父类文件夹
	 */
	public static Directory directory;
	public static IndexWriter indexWriter;

	public static void setDirectory(String indexWriterPath) throws IOException {
		// RAMDirectory ：内存中 FSDirectory:文件系统中

		File fileDir = new File(indexWriterPath);
		fileDir.mkdir();
		directory = FSDirectory.open(fileDir);
		indexWriter = getIndexWriter();
	}

	private static IndexWriter getIndexWriter() throws IOException {

		// 设置标准分词器 ,StandardAnalyzer 将词分成一个一个汉字

		// Analyzer analyzer=new SimpleAnalyzer(Version.LUCENE_47);
		// 设置IndexWriterConfig
		IndexWriterConfig indexWriterConfig = new IndexWriterConfig(
				Version.LUCENE_47, new StandardAnalyzer(Version.LUCENE_47));
		// indexWriterConfig.setRAMBufferSizeMB(3);//设置缓冲区大小
		return new IndexWriter(directory, indexWriterConfig);
	}

}
